﻿using System;

using Microsoft.Xna.Framework;

using Ah.Testudin.Engine.AI;
using Ah.Testudin.Engine.Events;
using Ah.Testudin.Engine.Events.Components;

namespace Ah.Testudin.Engine.Actors.Components
{
    public class AIComponent : IActorComponent
    {
        #region Private Member Variables

        private AIStateMachine _aiStateMachine;

        #endregion

        #region Constructors

        public AIComponent(
            Actor owner,
            AIStateMachine aiStateMachine,
            IEventManager eventManager)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            if (aiStateMachine == null)
            {
                throw new ArgumentNullException("aiStateMachine");
            }

            this.Owner = owner;

            _aiStateMachine = aiStateMachine;

            eventManager.TriggerEvent(
                new AIComponentCreatedEvent(
                    this));
        }

        #endregion

        #region IActorComponent

        public Actor Owner { get; private set; }

        public void Update(GameTime gameTime)
        {
            _aiStateMachine.Update(gameTime);
        }

        public void Dispose()
        {
        }

        #endregion

        #region Public Methods

        public void ChooseBestBehavior()
        {
            _aiStateMachine.ChooseBestBehavior();
        }

        #endregion
    }
}
